package com.norteksoft.erm.model;

import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * 数据操作类型定义
 * 
 * @hibernate.class table="ERM_DATAOPERATION"
 * @author Jiffy
 * 
 */
public class DataOperation extends BaseObject implements Comparable {

	private static final long serialVersionUID = 9090571917694195879L;

	public static final String OCCASION_BEFORE = "before";

	public static final String OCCASION_AFTER = "after";

	public static final DataOperation CREATE = new DataOperation(
			"创建", "CREATE", OCCASION_BEFORE, new Integer(0));

	public static final DataOperation SEARCH = new DataOperation(
			"检索", "SEARCH", OCCASION_AFTER, new Integer(1));

	public static final DataOperation VIEW = new DataOperation(
			"查看", "VIEW", OCCASION_AFTER, new Integer(2));

	public static final DataOperation MODIFY = new DataOperation(
			"修改", "MODIFY", OCCASION_AFTER, new Integer(3));

	public static final DataOperation DELETE = new DataOperation(
			"删除", "DELETE", OCCASION_AFTER, new Integer(4));
	
	public static final DataOperation LIST = new DataOperation(
			"列表", "LIST", OCCASION_AFTER, new Integer(5));



	private Long OID = new Long(-1);

	private String name;// 操作名称

	private String code;// 操作标识

	private String occasion;// 操作时机（之前/之后）

	private Integer mask;// 掩码

	private DataResource dataResource;// 所属数据资源类型

	public int hashCode() {
		return new HashCodeBuilder().append(OID).append(name).append(code)
				.append(occasion).append(mask).toHashCode();
	}

	public DataOperation(String name, String code, String occasion, Integer mask) {
		super();
		this.name = name;
		this.code = code;
		this.occasion = occasion;
		this.mask = mask;
	}

	public DataOperation() {
		super();
	}

	/**
	 * @hibernate.id column="OID" unsaved-value="-1" type="long"
	 * @hibernate.generator class="sequence"
	 * @hibernate.param name="sequence" value="ERM_SEQUENCE"
	 */

	public Long getOID() {
		return OID;
	}

	public void setOID(Long oid) {
		OID = oid;
	}

	/**
	 * @hibernate.property column="NAME" length="60" type="string"
	 *                     not-null="true"
	 * @return String
	 */

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @hibernate.property column="CODE" length="60" type="string"
	 *                     not-null="true"
	 * @return String
	 */

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	/**
	 * @hibernate.many-to-one name="dataResource" column="DATARESOURCEOID"
	 *                        class="com.norteksoft.erm.model.DataResource"
	 */

	public DataResource getDataResource() {
		return dataResource;
	}

	public void setDataResource(DataResource dataResource) {
		this.dataResource = dataResource;
	}

	/**
	 * @hibernate.property column="MASK" type="int" not-null="true"
	 * @return String
	 */
	public Integer getMask() {
		return mask;
	}

	public void setMask(Integer mask) {
		this.mask = mask;
	}

	/**
	 * @hibernate.property column="OCCASION" type="string" not-null="true"
	 * @return String
	 */

	public String getOccasion() {
		return occasion;
	}

	public void setOccasion(String occasion) {
		this.occasion = occasion;
	}

	public int compareTo(Object o) {
		return getMask().compareTo(((DataOperation) o).getMask());
	}

}
